#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAX_NUM 101
int sticks[MAX_NUM],used[MAX_NUM],N,sum,num,len;

bool comp(int a,int b){
	return a>b;
}

bool dfs(int cur,int left,int level){
	int i;
	if(left == 0){
		if(level == num-2){
			return true;
		}
		for(cur=0;used[cur];cur++)
		    ;
		used[cur] = 1;
		if(dfs(cur,len - sticks[cur],level+1))
		    return true;
		used[cur] = 0;
		return false;
	}else{
	    if(cur >= N-1)
			return false;
        for(i=cur;i<N;i++){
			if(used[i])
			    continue;
			if(sticks[i] == sticks[i-1] && !used[i-1])
				continue;
			if(sticks[i] > left)
			    continue;
			used[i] = 1;
			if(dfs(i,left-sticks[i],level)){
				return true;
			}
			used[i] = 0;
		}
		return false;
	}
}

int main(){
	int i,k,cnt,end=0;
	while(scanf("%d",&N),N){
		cnt = sum = 0;
		for(i=0;i<N;i++){
			scanf("%d",&k);
			if(k > 50)
			    continue;
			sum += k;
			sticks[cnt++] = k;
		}
		sort(sticks,sticks+N,comp);
		end = 0;
		for(len=sticks[0];len <= sum/2;len++){
			if(sum%len == 0){
				used[0] = 1;
				num = sum/len;
				if(dfs(0,len - sticks[0],0)){
					end = 1;
					printf("%d\n",len);
					break;
				}
				used[0] = 1;
			}
		}
		if(!end)
		    printf("%d\n",sum);
	}
	return 0;
}
